﻿namespace Truncation.Detector.WinForm.Controls
{
    public class Button : BaseControl
    {
        private System.Windows.Forms.Button _control;

        public Button(System.Windows.Forms.Control control)
        {
            _control = control as System.Windows.Forms.Button;
        }
        public override bool Measure()
        {
            const int padWidht = 17;
            const int padHeight = 9;
            if (_control.AutoSize == true)
                return true;
            int clientWidth = _control.Width - padWidht - _control.Padding.Left - _control.Padding.Right;
            if (_control.MaximumSize.Width > 0 && clientWidth > _control.MaximumSize.Width)
            {
                clientWidth = _control.MaximumSize.Width;
            }
            int clientHeight = _control.Height - padHeight - _control.Padding.Top - _control.Padding.Bottom;
            if (_control.MaximumSize.Height > 0 && clientHeight > _control.MaximumSize.Height)
            {
                clientHeight = _control.MaximumSize.Height;
            }

            return Measure(_control.Font, _control.Text, clientWidth, clientHeight);
        }
    }
}